package com.demo.zhlg.util;

import lombok.Data;

@Data
public class Result {
    public static final Integer SUCCESS = 100;
    public static final Integer AUTHENTICATION_FAILED = 102;
    public static final Integer WRONG_PASSWORD = 103;
    public static final Integer GENERAL_ERROR = 200;
    public static final Integer LOGIN_FAILED = 210;
    //...其他返回值类型

    Integer code;     // 返回值
    String  message;  // 错误信息
    Object  data;     // 携带的数据

    public static Result success(Object data){
        Result result = new Result();
        result.setCode(SUCCESS);
        result.setMessage("成功");
        result.setData(data);
        return result;
    }
    
    public static Result error(Integer code){
        Result result = new Result();
        result.setCode(code);
        result.setMessage("服务器错误");
        return result;
    }

    public static Result fail(String info){
        Result result = new Result();
        result.setCode(GENERAL_ERROR);
        result.setMessage(info);
        return result;
    }

    public static Result checkFailed(){
        Result result = new Result();
        result.setCode(AUTHENTICATION_FAILED);
        result.setMessage("未登录，请先登录");
        return result;
    }

    public static Result loginFailed() {
        Result result = new Result();
        result.setCode(LOGIN_FAILED);
        result.setMessage("用户名或密码错误");
        return result;
    }

    public static Result wrongPassword(){
        Result result = new Result();
        result.setCode(WRONG_PASSWORD);
        result.setMessage("密码错误");
        return result;
    }
}